package com.example.ai.embedding;

import org.springframework.ai.document.Document;
import org.springframework.ai.vectorstore.SearchRequest;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/verctor")
public class VectorDBController {
    @Autowired
    VectorStore vectorStore;
    @PostMapping("/similarSearch")
    public ResponseEntity<?> similarSearch(@RequestBody SimilarSearchReq req) {
        SearchRequest searchRequest = SearchRequest.builder()
                .query(req.getContent())
                .topK(req.getTopK())
                .similarityThreshold(req.getThreshold())
                .filterExpression(req.getFilter())
                .build();
        List<Document> similarDocuments = vectorStore.similaritySearch(searchRequest);
        return ResponseEntity.ok(similarDocuments);
    }
 }
